//
//  EJSOrderBaseViewController.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2018/1/3.
//  Copyright © 2018年 lifayu. All rights reserved.
//

#import "EJSOrderBaseViewController.h"
#import "EJSOrderModel.h"
#import "EJSCancelOrderRequest.h"
#import "EJSFinishOrderRequest.h"
#import "EJSPayOrderViewController.h"
#import "EJSCommentOrderViewController.h"

@interface EJSOrderBaseViewController ()

@end

@implementation EJSOrderBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)payFoyOrder:(EJSOrderModel *)order{
    EJSPayOrderViewController *payForOrderVC = [[EJSPayOrderViewController alloc] initWithNibName:@"EJSPayOrderViewController" bundle:nil];
    payForOrderVC.orderModel = order;
    [self.navigationController pushViewController:payForOrderVC animated:YES];
}

- (void)cancelOrder:(EJSOrderModel *)order{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否确认取消订单？" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertVC addAction:cancelAction];
    UIAlertAction *ensureAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        EJSCancelOrderRequest *req = [EJSCancelOrderRequest new];
        req.orderId = order.orderId;
        [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
            [self getOrderData];
        } failHandler:^(BaseResponse *response) {
            [[HUDHelper sharedInstance] tipMessage:response.message];
        }];
    }];
    [alertVC addAction:ensureAction];
    [self presentViewController:alertVC animated:YES completion:nil];
    
}

- (void)receivedOrder:(EJSOrderModel *)order{
    EJSFinishOrderRequest *req = [EJSFinishOrderRequest new];
    req.orderId = order.orderId;
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        [self getOrderData];
    } failHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance] tipMessage:response.message];
    }];
}

- (void)checkLogisticsOrder:(EJSOrderModel *)order{
   
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"订单已发货" message:[NSString stringWithFormat:@"订单发货时间：%@",order.deliveryTime] preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *ensureAction = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
      
    }];
    [alertVC addAction:ensureAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}

- (void)commentOrder:(EJSOrderModel *)order{
    EJSCommentOrderViewController *commentVC = [[EJSCommentOrderViewController alloc] initWithNibName:@"EJSCommentOrderViewController" bundle:nil];
    commentVC.orderId = order.orderId;
    [self.navigationController pushViewController:commentVC animated:YES];
}

- (void)getOrderData{
    
}

@end
